package java6681.bank;

import javax.swing.*;

public class CheckingAccount6681 extends Account6681 {
    private static long no = 501000;
    private double overdraft;

    {
        super.setId(++no + "");
    }

    public CheckingAccount6681() {
        super();
    }

    public CheckingAccount6681(String name, double balance, double overdraft) {
        super(name, balance);
        setOverdraft(overdraft);
//        super.setId(String.valueOf(no++));
    }

    public double getOverdraft() {
        return overdraft;
    }

    public void setOverdraft(double overdraft) {
        if (overdraft > 0) {
            this.overdraft = overdraft;
        } else {
//            this.overdraft = 0;
        }

    }


    public void withdraw6681(double getMoney) {
        double balance = super.getBalance();
        if (!checkMoney6681(getMoney)) {

        } else if (getMoney > balance + overdraft) {
            JOptionPane.showMessageDialog(null,
                    "金额必须大于0"
                    , "系统提示", JOptionPane.ERROR_MESSAGE);
        } else {
            setBalance(balance - getMoney);
        }
    }

    public double getCurrentOverdraft() {
        if (getBalance() > 0) {
            return overdraft;
        } else {
            return overdraft + getBalance();
        }
    }

    @Override
    public String toString() {
        return "信用卡账户" + "[" + super.toString() +
                " 透支额度 " + getOverdraft() +
                "]";

    }

}
